package com.atguigu.lease.web.admin.context;

import com.atguigu.lease.model.entity.SystemUser;
import org.springframework.stereotype.Component;

/**
 * ClassName:LoginUserContext
 * Package: com.atguigu.lease.web.admin.context
 * Description:
 *
 * @Author Makabaka
 * @Create 2024/9/25 20:11
 * @Version 1.0
 */

//ThreadLocal 存储数据 可以在同一个线程内共享
public class LoginUserContext {

    private static final ThreadLocal<SystemUser> userThreadLocal = new ThreadLocal<>();

    public static void setLoginUser(SystemUser systemUser) {
        userThreadLocal.set(systemUser);
    }

    public static SystemUser getLoginUser() {
        return userThreadLocal.get();
    }

    public static void clear() {
        userThreadLocal.remove();
    }
}
